package com.leyou.search.web;

import com.leyou.search.dto.SearchRequest;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 自动补全
     *
     * @param key
     * @return
     */
    @GetMapping("suggestion")
    public Mono<List<String>> generateSuggest(
            @RequestParam("key") String key) {
        return this.searchService.generateSuggest(key);
    }

    /**
     * 页面数据分页查询
     *
     * @param searchRequest
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> listData(
            @RequestBody SearchRequest searchRequest) {
        return this.searchService.listData(searchRequest);
    }

    /**
     * 页面搜索过滤条件的获取
     *
     * @param searchRequest
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String, List<?>>> listFilter(
            @RequestBody SearchRequest searchRequest) {
        return this.searchService.listFilter(searchRequest);
    }
}
